package hotgammon.view.tools;

import hotgammon.domain.*;
import hotgammon.view.*;
import hotgammon.view.figures.*;

import java.awt.event.MouseEvent;
import java.util.Iterator;
import java.util.List;

import minidraw.framework.*;
import minidraw.standard.*;

/** Tool to specifically to roll dices
 * 
 * Author Jim-Kyrre Benjaminsen
 */

public class GameStateTool extends NullTool implements StateTool {
	private BackgammonUserInterface objectServer;
	private CheckerMoveTool checkerMoveTool;
	private DieRollTool dieRollTool;

	public GameStateTool(BackgammonUserInterface ui) {
		this.objectServer = ui;

		checkerMoveTool = new CheckerMoveTool(objectServer);
		dieRollTool = new DieRollTool(objectServer);
		//objectServer.getEditor().
	}

	//public void mouseDown(MouseEvent e, int x, int y) {
	public void stateChange() {

		// check that you click on the dice
		/**Figure f = objectServer.getEditor().drawing().findFigure(e.getX(), e.getY());


    if (f instanceof CheckerFigure) { 
    	objectServer.getEditor().setTool(checkerMoveTool);
    } else if (f instanceof DieFigure) { 
    	objectServer.getEditor().setTool(dieRollTool);
    } */

		if(objectServer.getGame().getPlayerInTurn() == null || objectServer.getGame().getNumberOfMovesLeft() == 0){
			objectServer.getEditor().setTool(dieRollTool);
			objectServer.getEditor().showStatus("Throw the dice.");
		}else{
			objectServer.getEditor().setTool(checkerMoveTool);
			objectServer.getEditor().showStatus(
					"Player "+
					objectServer.getGame().getPlayerInTurn().toString()+
					": "+
					objectServer.getGame().getNumberOfMovesLeft()+
					" moves left"
					);
		}
		if(objectServer.getGame().winner() != Color.NONE){
			objectServer.getEditor().setTool(new NullTool());
			objectServer.getEditor().showStatus(
					"GAME OVER : The Winner is "+
					objectServer.getGame().winner()
					);
		}


	}

}
